﻿jQuery(document).ready(function () {
    AppMonthlyAlerts();
});

function AppMonthlyAlerts() {

    if ($("#moweb_mo_alert_email").val() == '') {
        $("#chkweb_mo_alert_email").attr('checked', false);
       
    }
    else {
        $("#chkweb_mo_alert_email").attr('checked', true);
        
    }


    if ($("#app_mo_alert_badge").val() == "1")
    {
        $("#chkMob_BadgeAlert_WebView").attr('checked', true);
    }
    else
    {
        $("#chkMob_BadgeAlert_WebView").attr('checked', false);
    }

    if ($("#app_mo_alert_popup").val() == "1") {
        $("#chkMob_PopupAlert_WebView").attr('checked', true);
    }
    else {
        $("#chkMob_PopupAlert_WebView").attr('checked', false);
    }
}


$("#moweb_mo_alert_email").live("keypress", function (e) {

    //If user starts to type in email textbox,then radio button for “Email” becomes active
    $("#chkweb_mo_alert_email").attr('checked', true);

});

$('#moweb_mo_alert_email').live("keyup", function (e) {

    if (e.which == 8 && this.value.length == 0) {
        $("#chkweb_mo_alert_email").attr('checked', false);
        $("#moweb_mo_alert_email").val('');
        //$("#web_mo_alert_email").val('');
     }
});

$("#chkweb_mo_alert_email").live("click", function (e) {

    if ($(this).is(':checked')) {

        $("#chkweb_mo_alert_email").val(1);
    }
    else {
        $("#chkweb_mo_alert_email").val(0);
        $("#moweb_mo_alert_email").val('');
        //$("#web_mo_alert_email").val('');
    }

});

$("#getWeekoftheMonth_WebView").live("change", function (e) {
    var selectedItem = $(this).val();
    $("#app_mo_alert_week").val(selectedItem);
    //window.scrollTo(0, 0);
});
$("#getDayoftheWeek_WebView").live("change", function (e) {
    var selectedItem = $(this).val();
    $("#app_mo_alert_day").val(selectedItem);
    //window.scrollTo(0, 0);
});
$("#getTimeoftheDay_WebView").live("change", function (e) {
    var selectedItem = $(this).val();
    $("#app_mo_alert_hour").val(selectedItem);
    //window.scrollTo(0, 0);
});

$("#chkMob_BadgeAlert_WebView").live("click", function (e) {
    if ($(this).is(':checked')) {

        $("#app_mo_alert_badge").val(1);
    }
    else {
         $("#app_mo_alert_badge").val(0);
    }

});
$("#chkMob_PopupAlert_WebView").live("click", function (e) {

    if ($(this).is(':checked')) {

         $("#app_mo_alert_popup").val(1);
    }
    else {
         $("#app_mo_alert_popup").val(0);
    }

});

$("#moweb_mo_alert_email").live("blur", function (e) {

    //check that email format  is correct
    if ($(this).val() != '') {
        var returnValue = isValidEmailAddress($(this).val());
        if (returnValue == false) {
            alert("Email address is not in the proper format for a valid email address.");
        }
        else {
            $("#moweb_mo_alert_email").val($(this).val());
            //$("#web_mo_alert_email").val($(this).val());
        }
    }
});

$("#finishandroid").click(function () {
    if ($("#chkweb_mo_alert_email").is(':checked') && $("#moweb_mo_alert_email").val() == '') {
        alert("You must enter the email.");
    }
    else {

        $("#UpdateAndroidMonthlyReminderForm").submit();
    }
});